<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Types';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="type-index">

    <h1><?= Html::encode($this->title) ?></h1>

    <p>
        <?= Html::a('Create Type', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,

        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'type_name',

            [
                'attribute' => 'type_sort',
                'label' => '排序'
            ],

            [
                'attribute' => 'isdisplay',
                'label' => '是否显示',
                'format' => 'raw',
                'value' => function ($model, $key, $index, $column) {
                    if ($model['isdisplay'] == 1) {
                        $url = Url::to([
                            'change-status',
                            'change' =>['id'=>$model['id'],'isdisplay'=>0],
//                            'field' => 'isdisplay'
                        ]);
                        $class = 'btn btn-info btn-xs btn-rounded';
//                        $confirm =Yii::t('app', '你确定要修改');
                    } else {
                        $url = Url::to([
                            'change-status',
                            'change' =>['id'=>$model['id'],'isdisplay'=>1],
//                            'field' => 'isdisplay'
                        ]);
                        $class = 'btn btn-default btn-xs btn-rounded';
//                        $confirm = Yii::t('app', '');
                    }
                    return Html::a($model->isdisplay?'是':'否', $url, [
                        'class' => $class,
//                        'data-confirm' => $confirm,
                        'data-method' => 'post',
                        'data-pjax' => '1',
                    ]);

                },
            ],

            [
                    'class' => 'yii\grid\ActionColumn',
                    'header' => '操作',
                    'template' => '{update} {delete} ',
            ],
        ],
    ]); ?>

</div>